//
//  FSCNetworkTools.swift
//  FamiliesSchoolConnection
//
//  Created by 花花蔡 on 2016/12/26.
//  Copyright © 2016年 com.HuaHuaCai. All rights reserved.
//

import UIKit
import AFNetworking

class FSCNetworkTools: AFHTTPSessionManager {

    typealias callBackClock = (_ data:Any?,_ error:Error?) -> ()
    
    ///网络工具单例属性
    static let shared:FSCNetworkTools = {
        //初始化工具类属性
        let instance = FSCNetworkTools(baseURL: URL(string: baseURLStr ?? ""))
        instance.responseSerializer.acceptableContentTypes?.insert("text/html")
        return instance
        
    }()
    
    
    
//MARK: - 封装网络方法
    
    //请求
    func request(url:String,parameters:Any?,finish:@escaping callBackClock) -> Void {
        
        //获得网络接口
        let urlStr = "zao/interface/"  + url
        //调用三方网络的方法请求数据
        get(urlStr, parameters: parameters, progress: nil, success: { (_, data) in
            
            finish(data,nil)
            
        }) { (_, err) in
            
            finish(nil, err)
            
        }
    }
    

//    //上传
//    func postData(url:String,paramter:Any?,body: @escaping (_ data:AFMultipartFormData?)->()  ,finish:@escaping (_ data:Any?,_ err:Error?)->() ) -> Void {
//       
//        //获得网络接口
//        let urlStr = "zao/interface/" + url
//        post(urlStr, parameters: paramter, constructingBodyWith: { (data) in
//            body(data)
//        }, progress: nil, success: { (_, data) in
//            finish(data,nil)
//        }) { (_, error) in
//            finish(nil,error)
//        }
   // }







}
